package com.ruoyi.security.service.backtest.gridtrading.strategy;

import com.ruoyi.security.enums.RiseFallTypeEnum;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * 倍数计算策略工厂
 * 使用工厂模式创建不同的策略实例
 * 
 * @author yeoman
 * @date 2025/2/4
 */
@Component
public class MultipleCalculationStrategyFactory {
    
    @Resource
    @Qualifier("percentageMultipleStrategy")
    private RiseFallTypeCalcStrategy percentageStrategy;

    @Resource
    @Qualifier("priceDifferenceMultipleStrategy")
    private RiseFallTypeCalcStrategy priceDifferenceStrategy;
    
    /**
     * 根据涨跌类型获取对应的策略
     * 
     * @param riseFallType 涨跌类型
     * @return 倍数计算策略
     */
    public RiseFallTypeCalcStrategy getStrategy(String riseFallType) {
        if (riseFallType.equals(RiseFallTypeEnum.BY_PERCENTAGE.getKey())) {
            return percentageStrategy;
        } else if (riseFallType.equals(RiseFallTypeEnum.BY_PRICE_DIFFERENCE.getKey())) {
            return priceDifferenceStrategy;
        }
        throw new IllegalArgumentException("不支持的涨跌类型: " + riseFallType);
    }
}

